package com.weilai.dao;

import com.weilai.domain.Likes;
import org.apache.ibatis.annotations.*;

@Mapper
public interface CommentsDao {
    // 点赞数增加1
    @Update("update comments set like_count = like_count + 1 where id = #{commentsId}")
    void incrementLikeCount(int commentsId);

    // 插入点赞记录
    @Insert("insert into likes (user_id, comments_id) values (#{userId}, #{commentsId})")
    void insertLikeRecord(int userId, int commentsId);

    // 检查用户是否已点赞
    @Select("select count(*) from likes where user_id = #{userId} and comments_id = #{commentsId}")
    int countUserLiked(int userId, int commentsId);

    // 根据用户id和评论id查询点赞记录
    @Select("select * from likes where user_id = #{userId} and comments_id = #{commentsId}")
    Likes selectLikeRecord(int userId, int commentsId);

    // 删除用户对评论的点赞
    @Delete("DELETE FROM likes WHERE user_id = #{userId} AND comments_id = #{commentsId}")
    int deleteLikeRecord(int userId, int commentsId);

    // 点赞数减少1
    @Update("update comments set like_count = like_count - 1 where id = #{commentsId}")
    void decrementLikeCount(int commentsId);

    //获取当前点赞数
    @Select("SELECT like_count FROM comments WHERE id = #{commentsId}")
    int getLikeCount(int commentsId);

    // 根据用户id删除评论
    @Delete("DELETE FROM comments WHERE user_id = #{userId}")
    int deleteCommentByUserId(int userId);
}
